'use strict' import botsService from '../bots' import { getBotById, deleteBotWithId } from './storageService' import { WrongInputError, NotFoundError, InternalError } from '../../utils/customErrors' import { Request } from 'express' /** * Operations on /bots/{id} */ export default { /**Returns a bot based on a single ID */ async getBot(req: Request) { if (req && req.params && req.params.id) { try { return await getBotById(req.params.id) } catch (error) { throw new NotFoundError(error) } } else { throw new WrongInputError('Invalid bot id.') } }, /**Updates or creates bot in the store. */ putBot: botsService.postBot, /**deletes a single bot based on the ID supplied */ async deleteBot(req: Request) { if (req.params && req.params.id) { try { return await deleteBotWithId(req.params.id) } catch (error) { throw new InternalError(error) } } else { throw new WrongInputError('Invalid bot id.') } } }